<?php

include_once 'Classes/PHPCodeProvider.php';

/*
 * Create an instance of the CodeGeneratorOptions class
 * using the default options for code generation.
 */

$options = new CodeGeneratorOptions();

/*
 * Create an instance of the IndentedTextWriter.
 * After the generateCodeFromStatement call
 * $writer will hold the generated code.
 */

$writer = new IndentedTextWriter();

/*
 * Create an instance of the PHPCodeProvider class
 */

$provider = new PHPCodeProvider();

/*
 * Expressions and statements to be used to create for statements
 */

$arr = new VariableReferenceExpression('arr');
$value = new VariableReferenceExpression('value');


/*
 * Example 1
 */

$foreach1 = new ForEachStatement($arr, $value);

$foreach1->Statements->add(
    new AssignStatement(
        $value, 
        new BinaryOperatorExpression(
            BinaryOperator::MULTIPLY, 
            $value, 
            new PrimitiveExpression(2))));

/*
 * Generate the code and output the result.
 */

$provider->generateCodeFromStatement($foreach1, $writer, $options);

echo 
    '<pre>' . str_replace(
        '<br />', '', highlight_string($writer->get_String(), true)) . 
    '<pre/>';


/*
 * The output should be:
 * 
 * 
 */

?>
